<?php
//obtengo cantidad de imagenes en la BD
$dbhandle = new PDO('sqlite:./datos/galeria.sqlite');
$result = $dbhandle->query("SELECT COUNT(*) FROM Pinturas");
$row = $result->fetch();
$cant_img = $row[0];


$numbers = range(1, $cant_img);
shuffle($numbers);
$slots = 0;
foreach ($numbers as $number) {

//En base a numero random x, determinar tamaño de cada imagen:
	$aleatorio = rand(0,99);
	if ($aleatorio <= 15)
	{
		$class = "double-size";
		$carpeta = "doubleSize";
		$slots = $slots + 4;
	}
	elseif($aleatorio <= 50)
	{
		$class = "double-height";
		$carpeta = "doubleHeight";
		$slots = $slots + 2;
	}
	else 
	{
		$class = "default-size";
		$carpeta = "defaultSize";
		$slots = $slots + 1;
	}
	//$result = $dbhandle->query("SELECT Imagen, NombreP FROM Pinturas WHERE Id = ".$number);
	$result = $dbhandle->query("SELECT Imagen, NombreP FROM Pinturas LIMIT 1 OFFSET ".($number-1));
	
	$row = $result->fetch();
	
	echo "<div class=".$class.">
				<a href=\"imagen.php?var=".$row[1]."\">
					<img src=\"upload/".$carpeta.$row[0]."\" alt=\"lala\">
				</a>
			</div>";
	
	if ($slots >= 80) break;
}

$dbhandle = null;
?>